package mscs.businesslogic.store;

import java.util.ArrayList;
import java.util.Date;

import mscs.data.Goods;
import mscs.data.Operations;
import mscs.data.Store;
public class ManageStore {
	Operations operations = new Operations();
	@SuppressWarnings("deprecation")
	public int getUsableDays(Goods goods) {
		ArrayList<Goods> goodsList = operations.getGoodsCollection(goods);
		Date date = goodsList.get(goodsList.size() - 1).getDesDate();
		return date.getDay() - (new Date()).getDay();
    }
	public int getRuleDay(Goods goods) {
		return operations.getGoodsCollection(goods).get(operations.getGoodsCollection(goods).size() - 1).getEntDate().getDay() - (new Date()).getDay();
	}
    public int preDays(Goods goods) {
    	//流通总量
        int flow = operations.getPreSum(goods) + operations.getSum(goods) - (new Store()).getSum(goods);
        //尺度天数
        int ruleDay = getRuleDay(goods);
        //每天流通量
        int eveFlow = flow / ruleDay;
        if (eveFlow > 0) {
        	return eveFlow > getUsableDays(goods) ? getUsableDays(goods) : eveFlow; 
        } else {
        	return 0;
        }
        
    }
    public double preDesPer(Goods goods) {
        int usableDay = getUsableDays(goods);
        int preDay = preDays(goods);
        if (preDay > usableDay) {
        	return (preDay - usableDay) * 1.0 / preDay;
        } else {
        	return 0;
        }
    }
}
